-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow path-based config overrides #162
Allow path-based config overrides #162
Conversation
…ed-config-overrides
@@ -9,6 +9,10 @@ | |||
def record_results! | |||
title = RSpec::OpenAPI.title | |||
@path_records.each do |path, records| | |||
# Look for a path-specific config file and run it. | |||
config_file = File.join(File.dirname(path), RSpec::OpenAPI.config_filename) | |||
eval(File.read(config_file)) if File.exist?(config_file) |
Check notice
Code scanning / Rubocop
The use of eval represents a serious security risk. Note
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #162 +/- ##
==========================================
+ Coverage 96.79% 96.82% +0.02%
==========================================
Files 14 14
Lines 437 441 +4
Branches 97 98 +1
==========================================
+ Hits 423 427 +4
Misses 14 14 ☔ View full report in Codecov by Sentry. |
Could you let me know? # open_api_v1.rb
RSpec::OpenAPI.title = 'API v1 (legacy, unmaintained)'
RSpec::OpenAPI.path = 'doc/schema_v1.yaml'
# open_api_v2.rb
RSpec::OpenAPI.title = 'API v2'
RSpec::OpenAPI.path = 'doc/schema_v2.yaml' If so, RSpec::OpenAPI.path = -> (example) {
case example.file_path
when %r[spec/requests/api/v1/] then 'doc/openapi/v1.yaml'
when %r[spec/requests/api/v2/] then 'doc/openapi/v2.yaml'
else 'doc/openapi.yaml'
end
} |
Basically yes, that's what we're looking for. But my understanding is that path splitting just tells the gem where to dump the schemas for each API. We need to be able to change the title, server locations, etc. I think this is also what ipepe is asking for in #161. A little more context: We are a benefits company and have several API's such as enrollments, mobile, etc. They all live in the same base repo, so we somehow have to be able to generate documentation with the right titles, etc. for each of them. Right now, we have a config file in our |
Closes #161
Complex API's often use different server paths and have specific title and other information for different services. The purpose of this PR is to allow for such configurations to be overridden within each path defined in
RSpec::OpenAPI.path
. The PR also allows for the naming of the config file (defaulting torspec_openapi.rb
).While the current initializer can define all the paths and common settings like the request and response headers, security schemes, and others, the path-based configuration files can be used to define server and other path/service-specific information.